package timbap.visualizer.api.model;

import java.io.File;

/**
 * The <code>PlaylistEntry</code> class represents an entry of the
 * currently active playlist. It holds a reference to the
 * audio file and stores the most important meta data. 
 *
 * @author  Andreas Pabst
 * @see     timbap.visualizer.api.context.playlist.PlaylistManager
 */
public class PlaylistEntry {

    File audioFile;
    
    ArtworkData artworkData;
    String artistName = "";
    String songTitle = "";
    String albumTitle = "";
    String songGenre = "";
    int yearReleased = -1;
    int totalTimeInSeconds = -1;
    
    
    public PlaylistEntry(File pAudioFile) {
        audioFile = pAudioFile;
    }

    public File getAudioFile() {
        return audioFile;
    }

    /**
     * use TextureCacheManager.getArtworkData(PlaylistEntry) instead
     */
    @Deprecated
    public ArtworkData getArtworkData() {
		return artworkData;
	}

    /**
     * use TextureCacheManager.putArtworkData(PlaylistEntry) instead
     */
    @Deprecated
    public void setArtworkData(ArtworkData pArtworkData) {
		this.artworkData = pArtworkData;
	}

    public String getArtistName() {
        return artistName;
    }

    public void setArtistName(String pArtistName) {
        this.artistName = pArtistName;
    }

    public String getSongTitle() {
        return songTitle;
    }

    public void setSongTitle(String pSongTitle) {
        this.songTitle = pSongTitle;
    }

    public int getTotalTimeInSeconds() {
        return totalTimeInSeconds;
    }

    public void setTotalTimeInSeconds(int totalTimeInSeconds) {
        this.totalTimeInSeconds = totalTimeInSeconds;
    }
    
	public String getAlbumTitle() {
		return albumTitle;
	}

	public void setAlbumTitle(String albumTitle) {
		this.albumTitle = albumTitle;
	}

	public String getSongGenre() {
		return songGenre;
	}

	public void setSongGenre(String songGenre) {
		this.songGenre = songGenre;
	}

	public int getYearReleased() {
		return yearReleased;
	}

	public void setYearReleased(int yearReleased) {
		this.yearReleased = yearReleased;
	}

    public String toM3uExtInfString() {
        return "#EXTINF:-1," + this.toString() + "\n" + audioFile.getAbsolutePath();
    }
    
    public String toString() {
    	return getArtistName() + " - " + getSongTitle();
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PlaylistEntry that = (PlaylistEntry) o;

        if (!audioFile.toURI().toASCIIString().equals(that.audioFile.toURI().toASCIIString())) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        return audioFile.toURI().toASCIIString().hashCode();
    }
}
